package org.dydl.dao.system.repository;

import java.sql.Timestamp;

import org.dydl.model.system.Delivery;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;


@Repository
public interface ITranslateRepository extends CrudRepository<Delivery, Integer>,JpaSpecificationExecutor<Delivery>{

	@Query(value = "FROM Delivery dl",countQuery = "SELECT count(dl.id) FROM Delivery dl")
	Page<Delivery> getDeliveryList(Pageable pageable);
	
	@Query(value = "FROM Delivery dl WHERE dl.deliveryNoteNo LIKE :deliveryNoteNo" ,countQuery = "SELECT count(dl.id) FROM Delivery dl WHERE dl.deliveryNoteNo LIKE :deliveryNoteNo")
	Page<Delivery> getDeliveryListLike(@Param("deliveryNoteNo")String deliveryNoteNo, Pageable pageable);
	
	@Query(value = "SELECT * FROM delivery WHERE DELIVERY_NOTE_NO = :deliveryNoteNo" ,nativeQuery = true)
	Delivery findByDeliveryNoteNo(@Param("deliveryNoteNo")String deliveryNoteNo);
	
	@Modifying
	@Query(value = "UPDATE delivery set STATUS = 1 WHERE ID = :id", nativeQuery = true)
	void changeExamineStatus(@Param("id") int id);
	
	@Modifying
	@Query(value = "UPDATE delivery set STATUS = 2, RECIPIENT = :recipient, SIGN_TIME = :signTime WHERE DELIVERY_NOTE_NO= :deliveryNoteNo", nativeQuery = true)
	void doSign(@Param("deliveryNoteNo")String deliveryNoteNo,@Param("recipient")String recipient,@Param("signTime")Timestamp signTime);
	
}
